package com.tudouji.project.mt.domain;

import java.util.Date;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.flow.service.utils.DateUtils;
import com.tudouji.common.exception.CustomException;
import com.tudouji.framework.aspectj.lang.annotation.Excel;
import com.tudouji.framework.web.domain.BaseEntity;
import com.tudouji.project.customer.domain.Customer;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

/**
 * 美团店铺对象 mt_shop
 * 
 * @author tudouji
 * @date 2023-11-21
 */
@Data
@Slf4j
public class MtShop extends BaseEntity
{
    private static final long serialVersionUID = 1L;

    /** $column.columnComment */
    private Long id;

    /** 店铺编码 */
    @Excel(name = "店铺编码")
    private String code;

    /** 店铺名称 */
    @Excel(name = "店铺名称")
    private String name;

    /** 组织Id */
    @Excel(name = "组织Id")
    private Long orgId;


    /** 组织名称 */
    @Excel(name = "组织名称")
    private String orgName;
    /** 美团组织Id */
    @Excel(name = "美团组织Id")
    private Long mtOrgid;
    @Excel(name = "美团组织编码")
    private String mtOrgcode;

    /** 用户Id */
    @Excel(name = "用户Id")
    private Long sysuserid;

    /** 用户名称 */
    @Excel(name = "用户名称")
    private String sysusernickname;

    /** 部门id */
    @Excel(name = "部门id")
    private Long deptId;

    /** 部门名称 */
    @Excel(name = "部门名称")
    private String deptName;

    /** 销售客户id */
    @Excel(name = "销售客户id")
    private Long customerId;

    /** 销售客户name */
    @Excel(name = "销售客户name")
    private String customerName;

    /** 入库单已同步日期 */
    @JsonFormat(pattern = "yyyy-MM-dd")
    @Excel(name = "入库单已同步日期", width = 30, dateFormat = "yyyy-MM-dd")
    private Date whinAsyndate;

    /** 出库单已同步日期 */
    @JsonFormat(pattern = "yyyy-MM-dd")
    @Excel(name = "出库单已同步日期", width = 30, dateFormat = "yyyy-MM-dd")
    private Date whoutAsyndate;

    /** 菜品消耗同步日期 */
    @JsonFormat(pattern = "yyyy-MM-dd")
    @Excel(name = "菜品消耗同步日期", width = 30, dateFormat = "yyyy-MM-dd")
    private Date foodconsumAsyndate;

    /** 拉取日期 */
    @JsonFormat(pattern = "yyyy-MM-dd")
    @Excel(name = "拉取日期", width = 30, dateFormat = "yyyy-MM-dd")
    private Date pulldate;

    private Date pulldateEnd;

    /** 数据拉取状态	1 – 成功 0 – 初始/失败 */
    @Excel(name = "数据拉取状态	1 – 成功 0 – 初始/失败 ")
    private Integer pullState;

    /** 推送日期 */
    @JsonFormat(pattern = "yyyy-MM-dd")
    @Excel(name = "推送日期", width = 30, dateFormat = "yyyy-MM-dd")
    private Date pushdate;

    /** 推送步长 */
    private Integer pushDays;

    /** 数据推送状态	1 – 成功 0 – 初始/失败 */
    @Excel(name = "数据推送状态	1 – 成功 0 – 初始/失败 ")
    private Integer pushState;



    /**
     *  pushState的低1/2/3位分别表示3种推送状态
     * 低1位表示出库单推送状态，2位表示入库单 3位表示销售订单+生产加工订单
     */
    public  static final int init_state = 1<<0;
    public static final int whin_state = 1<<1;
    public static final int whout_state = 1<<2;
    public static final int sell_state = 1<<3;
    public static final int cost_state = 1<<4;

    /**
     * 获取某一推送业务状态，如果某一状态==1 则返回true，否则false
     * @param type  whin_state / whout_state / sell_state之一
     * @return
     */
    public boolean isPushFinished(int type){
        if (pushState == null){
            return false;
        }
        return (type & pushState) == type;
    }

    /**
     * 判断所有业务是不是都同步成功
     * @return
     */
    public boolean isAllPushFinished(){
        return isPushFinished(whin_state) && isPushFinished(whout_state)
                && isPushFinished(sell_state);
    }

    /**
     * 设置某一推送业务状态
     * @param type     whin_state / whout_state / sell_state
     * @param state    0 / 1
     */
    public void setPushState(int type,int state){
        if(pushState==null) pushState = init_state;
        if(state==1){
            pushState |= type;
        }else{
            pushState = pushState & ~type;
        }
    }

    /**
     * 获取某一推送业务状态，如果某一状态==1 则返回true，否则false
     * @param type  whin_state / whout_state / sell_state之一
     * @return
     */
    public boolean isPullFinished(int type){
        if (pullState == null){
            return false;
        }
        return (type & pullState) == type;
    }

    /**
     * 判断所有业务数据是不是都拉取成功
     * @return
     */
    public boolean isAllPullFinished(){
        return isPullFinished(whin_state) && isPullFinished(whout_state)
                && isPullFinished(sell_state) && isPullFinished(cost_state);
    }

    /**
     * 设置某一推送业务状态
     * @param type     whin_state / whout_state / sell_state
     * @param state    0 / 1
     */
    public void setPullState(int type,int state){
        if(pullState==null) pullState = init_state;
        if(state==1){
            pullState |= type;
        }else{
            pullState = pullState & ~type;
        }
    }



    public static void main(String[] args) {
        MtShop mtShop = new MtShop();
        mtShop.setPushState(sell_state,1);
        mtShop.setPushState(whin_state,1);
        System.out.println(mtShop.isPushFinished(whin_state));
        System.out.println(mtShop.pushState);
        mtShop.setPushState(whout_state,1);
        System.out.println(mtShop.isPushFinished(whout_state));
        System.out.println(mtShop.pushState);

        System.out.println(mtShop.isPushFinished(sell_state));
        System.out.println(mtShop.isAllPushFinished());
        System.out.println(mtShop.pushState);

    }
    /** $column.columnComment */
    @Excel(name = "状态")
    private Integer status;
}
